$(function() {
    init_vue();
});
function init_vue() {
    var vue = new Vue({
        el : "#myapp",
        data : {
            user:null,
            config:[],
            currentView:'',
        },
        events : {
            'refreshUser':function (obj) {
                this.user[obj.key] = obj.value;
            }
        },
        methods : {
            init : function() {
                var t = this;
                postMsg(root+"/user/toinfo", {
                    user_id:id,
                }, function(i) {
                    close_layuiLayerLoad();
                    t.user = i.user;
                    t.currentView = i.currentView;
                    t.config = i.config;
                });
            },
            toggle : function(v){
                this.currentView = v;
            },
            changeState : function(id, state) {
                var t = this;
                layuiLayerLoad();
                postMsg(root+"/user/changeState", {id:id, state:state}, function(i) {
                    if (i == 1) {
                        t.user.state = state;
                        if (state == 1) {
                            $.scojs_message('账号已停用', $.scojs_message.TYPE_ERROR);
                        } else if (state == 0) {
                            $.scojs_message('账号已启用', $.scojs_message.TYPE_OK);
                        }
                    }
                    close_layuiLayerLoad();
                });
            },
            reset_pass: function (id) {
                layer.confirm('确认要为用户重置密码吗？', {
                    btn: ['确认','取消'] //按钮
                    ,closeBtn: 0
                }, function(index){
                    layer.close(index);
                    showLoad();
                    postMsg(root+"/user/resetPass", {id:id}, function(i) {
                        if (i.code == 1) {
                            $.scojs_message(i.msg, $.scojs_message.TYPE_OK);
                        }
                        hideLoad();
                    });
                });
            },
            capitalAdjusted : function (type) {
                var t = this;
                t.$broadcast('openUserCapitalAdjustedWin', {id:t.user.id, type:type, balance:0});
            }
        }
    });
    vue.init();
}